﻿<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:CodeGenerator="http://sapura.com.my/codegenerator"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl"
                xml:space="preserve">

    <xsl:output method="xml"
                indent="yes" />

    <xsl:template match="Metadata" ><xsl:apply-templates mode="Requirements" /></xsl:template>

    <xsl:template match="Object[@IsSelected='True']"
                  mode="Requirements"><xsl:text disable-output-escaping="yes"><![CDATA[//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:3.2.0
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

// 
// This source code was auto-generated by Sapura Defense Technologies - Code Generator, Version 3.2.0.
// 

namespace ]]></xsl:text><xsl:value-of select="../@Namespace" /><![CDATA[.ViewModel.]]><xsl:value-of select="CodeGenerator:NormalizeName(@Namespace)" /><![CDATA[
{
    using System;

]]><![CDATA[
    public partial class ]]><xsl:value-of select="CodeGenerator:NormalizeName(@Name)" /><![CDATA[ViewModel
        : ObservableObject
    {]]><xsl:apply-templates select="Property"
                         mode="DependencyProperty" /><![CDATA[    };
};]]><xsl:value-of select="CodeGenerator:Save(concat('\ViewModel\', CodeGenerator:NormalizeName(@Namespace)), concat(CodeGenerator:NormalizeName(@Name), 'ViewModel.cs'))" />
</xsl:template>

        <xsl:template match="Property"
                  mode="DependencyProperty"><![CDATA[
        private ]]><xsl:call-template name="ClrDataType" /><![CDATA[ _]]><xsl:value-of select="@Name" /><![CDATA[;
        public ]]><xsl:call-template name="ClrDataType" /><![CDATA[ ]]><xsl:value-of select="CodeGenerator:NormalizeName(@Name)" /><![CDATA[
        {
            get
            {
                return this._]]><xsl:value-of select="@Name" /><![CDATA[;
            }
            set
            {
                this._]]><xsl:value-of select="@Name" /><![CDATA[ = value;

                base.OnPropertyChanged("]]><xsl:value-of select="@Name" /><![CDATA[");
            }
        }
]]></xsl:template>

<xsl:template name="ClrDataType"><xsl:choose><xsl:when test="@DataType='character varying'">String</xsl:when><xsl:when test="@DataType='character'">String</xsl:when><xsl:when test="@DataType='bytea'">byte[]</xsl:when><xsl:when test="@DataType='xml'">String</xsl:when><xsl:when test="@DataType='xml'">String</xsl:when><xsl:when test="@DataType='text'">String</xsl:when><xsl:when test="@DataType='timestamp with time zone'">DateTime</xsl:when><xsl:when test="@DataType='timestamp without time zone'">DateTime</xsl:when><xsl:when test="@DataType='date'">DateTime</xsl:when><xsl:when test="@DataType='integer'">Int32</xsl:when><xsl:otherwise><xsl:value-of select="translate(@DataType,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" /></xsl:otherwise></xsl:choose></xsl:template>

</xsl:stylesheet>